<template>
  <div class="bigbox">
    <div class="top">
      <el-form ref="form" label-width="80px">
        <el-form-item label="属性分类">
          <el-select v-model="form.region" placeholder="请选择分类">
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="item in getCategoryLists"
              :key="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="属性名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="addFn">保存</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { addAttrbute, getCategoryLists ,getAttrInfo} from "../../request/httpApi";
export default {
  data() {
    return {
      form: {
        region: "",
        name: "",
      },
      getCategoryLists: [],
      aid: 0,
    };
  },

  created() {
     console.log(this.$route);
    this.aid = this.$route.params.aid;
    // 分类渲染
  getAttrInfo({
     id:this.aid,
   }).then((res)=>{
     console.log(res);
     this.form.region = res.data.attribute_category_id,
     this.form.name = res.data.name
    }),
     getCategoryLists().then((res)=>{
        //   console.log(res);
          this.getCategoryLists = res.data;
      })
  },
  methods: {
    // 页面渲染显示
    addFn() {
        addAttrbute({
          id:this.aid,
      name: this.form.name,
      attribute_category_id: this.form.region
    }).then((res) => {
      console.log(res);
    });
    }
    
    


  },
};
</script>

<style lang="less" scoped>
.bigbox {
  background: #fff;
  .top {
    padding-top: 20px;
    padding-bottom: 30px;
    .el-input {
      //   margin-left: 15px;
      width: 217px;
      margin-right: 15px;
      /deep/ .el-input__inner {
        height: 36px;
        line-height: 36px;
        border-radius: 5px;
      }
    }
  }
}
</style>
